home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Yerk 3.6.6 / Asm source / TopLevel < prev    next >
Encoding:
Text File  |  1993-06-06  |  5.2 KB  |  143 lines  |  [TEXT/YERK]

  1. nk lines
  2. : KILLEOLS  ( -- )
  3.     BEGIN
  4.         nextToken 4 = not
  5.     UNTIL
  6. ;
  7.  
  8. : DOMIDDLE
  9.     msg" top"
  10.     errflag
  11.     IF                                     \ if error then 
  12.         211 asmError                       \    abort
  13.         abort
  14.     ELSE                                   \ else
  15.         moveBack                           \    set up pass 2
  16.         2 initP
  17.     THEN
  18. ;
  19.  
  20. \ Assemble instructions, main control loop 
  21. : ASM   { \ mnemonic endFlag -- }
  22.     false -> endFlag
  23.     BEGIN
  24.         endFlag
  25.         IF                                 \ if end flag then
  26.             false                          \    get out of loop
  27.         ELSE                               \ else
  28.             KillEols                       \    get rid of blank lines
  29.             start: token                   \    get a token
  30.             EndAddr EndLen get: token s= not val" ENDflag F=Found"
  31.         THEN                               \    if end of asm code then exit
  32.     WHILE
  33.         token query: codes -> mnemonic     \ get label of opcode
  34.         mnemonic val" mnemonic is" 0=      \ check for label
  35.         IF                                 \ Label
  36.             msg" It's a label!"
  37.             pass 1 =
  38.             IF                                       \ if pass 1 then
  39.                 codePos 2* token enter: symtab       \ put label on simtab
  40.             THEN
  41.         ELSE
  42.             opsize: mnemonic -> opSize
  43.             mnemonic val" final mnemonic is" 0= 
  44.             IF
  45.                 true -> endFlag                      \ end of asm code
  46.             ELSE
  47.                 pass 1 =
  48.                 IF
  49.                     length: mnemonic \ dup . cr      \ for debuging
  50.                     ++> codePos                      \ add length to codepos
  51.                 ELSE
  52.                     here -> keephere                 \ builds bit codes
  53.                     build: mnemonic
  54.                     here keephere - ++> codePos
  55.                 THEN
  56.             THEN
  57.         THEN
  58.     REPEAT
  59.     pass 1 =
  60.     IF
  61.         doMiddle
  62.         ASM msg" after pass-2"                   \ starts pass 2 recursively
  63.     ELSE
  64.         msg" pre-next"
  65.         [compile] next,
  66.         msg" post-next"
  67.     THEN
  68. ;
  69.  
  70. TRUE value InitASM?     \ jaf 12/13 has ASM been init'd?
  71.  
  72. 2 0 0 to: next.state
  73. 1 0 1 to: next.state
  74. 0 0 2 to: next.state
  75. 0 0 3 to: next.state
  76. 0 1 0 to: next.state
  77. 1 1 1 to: next.state
  78. 0 1 2 to: next.state
  79. 0 1 3 to: next.state
  80. 2 2 0 to: next.state
  81. 2 2 1 to: next.state
  82. 0 2 2 to: next.state
  83. 0 2 3 to: next.state
  84.  
  85. 0 0 0 to: action
  86. 0 0 1 to: action
  87. 2 0 2 to: action
  88. 4 0 3 to: action
  89. 1 1 0 to: action
  90. 0 1 1 to: action
  91. 1 1 2 to: action
  92. 1 1 3 to: action
  93. 0 2 0 to: action
  94. 0 2 1 to: action
  95. 3 2 2 to: action
  96. 3 2 3 to: action
  97.  
  98. : InitASM { \ xecho -- }     \ jaf 12/13 created asm init word
  99.  
  100. new: token
  101. decho -> xecho -echo    \ Preserve echo status
  102. " Operands" loadOps                   \ get operands in "operands"
  103. " AsmCodes" loadcodes                 \ get opcode codes in AsmCodes
  104. false -> InitASM?
  105. xecho -> decho          \ Restore echo status
  106. ;
  107.  
  108. : EndASM    \ jaf 12/13 use when done with ASM
  109.     dispose: codes
  110.     dispose: operands
  111.     dispose: symTab
  112.     release: token
  113.     TRUE -> INITASM?
  114. ;
  115.  
  116. 0 value keepLine
  117. \ :CODE - word exported to dictionary. Begins compilation of code word
  118. : :CODE
  119.     " ;CODE" -> endLen -> endAddr
  120.     dispose: symTab
  121.     create                      \ start the :code definition
  122.     line# -> keepLine
  123.     0 -> line#
  124.     InitASM? IF InitASM THEN    \ jaf 12/13 init ASM if not already done
  125.     1 initP
  126.     asm                         \ does the work
  127.     msg" post-asm"
  128.     line# 2/ keepLine + -> line#
  129.     query: topfile drop
  130. ;
  131.  
  132. \ ADD-HDR-CODE - this word ,'s in the appropriate machine instructions to 
  133. \  set up a code method definition. Whatever they might be.
  134. : ADD-HDR-CODE
  135.     here 24 + ,     \ 0CFA - for public objects
  136.     here 4+ ,       \ 1CFA - for ivars
  137.     $ 301C w,       \ move.w (a4)+,d0
  138.     $ 6C02 w,       \ bge +2
  139.     $ 4280 w,       \ clr.l d0
  140.     $ 2445 w,       \ movea.l d5,a2
  141.     $ 2452 w,       \ movea.l (a2),a2
  142.     $ D5C0 w,       \ adda.l d0,a2
  143.     $ 4EFA0